﻿using System.IO;

namespace FizzBuzz.OutputProviders
{
    public class FileProvider:IOutputProvider
    {
        public string fileName { get; set; }
        private readonly string destination;

        public FileProvider(string destination,string fileName)
        {
            this.fileName = fileName;
            this.destination = destination;
        }

        public void Render(int value, string text)
        {
            if(!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }

            string filePath = destination;
            if(!filePath.EndsWith(@"\")) filePath += @"\";

            filePath += fileName;
            using (var sw = new StreamWriter(filePath, true))
            {
                sw.WriteLine(text);
                sw.Flush();
            }
                        
        }

        
    }
}